package com.zbkj.admin.controller.merchant;

import cn.hutool.json.JSONException;
import com.zbkj.admin.model.req.ProductTabAddRequest;
import com.zbkj.admin.vo.OptionItemVO;
import com.zbkj.dal.annotation.LogControllerAnnotation;
import com.zbkj.dal.base.enums.MethodType;
import com.zbkj.dal.base.page.CommonPage;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.dal.entity.product.ProductTab;
import com.zbkj.dal.pojo.request.*;
import com.zbkj.dal.pojo.response.*;
import com.zbkj.service.service.ProductService;
import com.zbkj.service.service.ProductTabService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 商户端商品控制器
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/admin/merchant/product/tab")
@Api(tags = "商户端商品Tab控制器") //配合swagger使用
public class MerchantProductTabController {

    @Autowired
    private ProductService productService;
    @Autowired
    private ProductTabService productTabService;

    @ApiOperation(value = "获取全部启用的商品Tab")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<List<OptionItemVO>> listEnableProductTabs() {
        List<ProductTab> allEnableProductTabs = productTabService.getAllEnableProductTabs(null);
        List<OptionItemVO> collect = allEnableProductTabs.stream().map(OptionItemVO::buildByProductTab).collect(Collectors.toList());
        return CommonResult.success(collect);
    }
}



